package com.asia5b.a5mall.middleware.logic.viewmodel.member

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleNetParams
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.base.ResultModel
import com.asia5b.a5mall.middleware.model.member.PointModel
import io.reactivex.functions.Consumer

class PointListActivityVM : SimpleViewModel() {

    private var page = 1
    private var sumPage = 1000

    val getDatasResultLiveData = MutableLiveData<ResultModel<ArrayList<PointModel>>>()
    fun getDatas(refresh: Int) {
        if (refresh <= 1) {
            page = 1
            sumPage = 1000
        }
        if (page > sumPage) {
//            loadMvpView.dismissLoadingBar()
            loadingLiveData.value = 1
            return
        }

        val observable = memberApi.getPointList(page)

        baseSubscribe(observable, SimpleNetParams(isShowLoading = refresh == 0), Consumer { resultModel ->
            sumPage = resultModel.sumPage
            page = resultModel.page + 1
//            providerView().getDatasResult(resultModel.data)
            getDatasResultLiveData.value = resultModel
        })
    }
}